/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package horde.internalResources.dictionaries;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * Resource Bundle
 * @author Arturo Mazón and Andres Picazo
 */
public class dictionary {    

    /**
     * Default builder
     */
    public dictionary() {
    }

    // <editor-fold defaultstate="collapsed" desc="Set Bundle by language">
    /**
     * Sets a new language to the current ResourceBundle
     * @param locale Parameter to choose de language. Example: new Locale("es","ES")
     * @see java.util.Locale
     * @see java.util.ResourceBundle;
     */
    public static void setBundle(Locale locale){
		BUNDLE_NAME = "horde/standard/resources/graphics/dictionaries/dictionary_"+locale.getLanguage()+"_"+locale.getCountry();
		RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
	}

    /**
     * Sets a new language to the current ResourceBundle
     * @param l Parameter to choose de language. Can take the values "EN", "ES"
     */
    public static void setBundle(String l) {
        if (l.equals("ES")) {
            BUNDLE_NAME = languageRootES;
        } else if (l.equals("US")) {
            BUNDLE_NAME = languageRootUS;
        }
        RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
    }

    // </editor-fold>


    // <editor-fold defaultstate="collapsed" desc="Get Strings">
    /**
     * Gets a string from the language properties for the specified key
     * @param key
     * @return String from the language properties for the specified key
     * @exception MissingResourceException if no valid key
     */
    public static String getString(String key) {
        try {
            return RESOURCE_BUNDLE.getString(key);
        } catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }

    /**
     * Gets a string from the language properties for the specified key
     * @param key
     * @param params Format options
     * @see java.text.MessageFormat
     * @return String from the language properties for the specified key and with the format specified (params)
     * @exception MissingResourceException if no valid key
     */
    public static String getString(String key, Object[] params) {
        if (params == null) {
            return getString(key);
        }
        try {
            return MessageFormat.format(getString(key), params);
        } catch (Exception e) {
            return "!" + key + "!";
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Atributes">
    private static final String languageRootES = "horde/internalResources/dictionaries/dictionary_es_ES";
    private static final String languageRootUS = "horde/internalResources/dictionaries/dictionary_en_US";
    private static String BUNDLE_NAME = languageRootUS;
    private static ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
    private Locale localeActual = new Locale("es","ES");
    // </editor-fold>
}
